package com.honeywen.mymvc.opera;

import com.google.common.collect.Lists;
import org.apache.commons.io.FileUtils;

import java.io.*;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author wangwei
 * @date 2019/11/14
 */
public class FileReadTest {



    public static void main(String[] args) {
        // 八月注册未申请的
        String filepath = "/Users/wangwei/test/ts/registere_no_apply_august.txt";
        // 所有申请的ID
        String filepath2 = "/Users/wangwei/test/ts/applyids.txt";

        // 保存地址
        String filepath3 = "/Users/wangwei/test/ts/noapplyid333.txt";

        File file = new File(filepath);
        File file2 = new File(filepath2);
        File file3 = new File(filepath3);




        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file)));


            BufferedReader reader2 = new BufferedReader(new InputStreamReader(new FileInputStream(file2)));

            Set<String> loanedList = new HashSet<>();

            String line2 = null;
            while((line2 = reader2.readLine()) != null) {

                loanedList.add(line2);

            }

            System.out.println("applyed-->" + loanedList.size());


            List<String> list = Lists.newArrayList();

            String line = null;
            int count = 0;
            while ((line = reader.readLine()) != null) {
                count++;

                String id = line.split(",")[0];
                if (loanedList.contains(id)) {
                    continue;
                }
                list.add(line);

            }


            System.out.println("origin-->" + count);
            System.out.println("noapply-->" + list.size());

            FileUtils.writeLines(file3, list);

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
